package org.collection.newcollection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.google.common.collect.ForwardingList;

public class ForwardingTest {

	public static void main(String[] args) {
		AddLoggingList<Integer> loggingList =new AddLoggingList<>();
		loggingList.add(1);
		loggingList.add(0, 3);
		loggingList.add(0, 2);
		loggingList.add(4);
		System.out.println(loggingList.toString());

	}
	
	public static class AddLoggingList<E> extends ForwardingList<E> {
		final List<E> delegate;
		
		public AddLoggingList() {
			delegate = new ArrayList<E>();
		}
		
		@Override
		protected List<E> delegate() {
			return delegate;
		}
		
		@Override
		public void add(int index, E elem) {
			//log(index, elem);
			System.out.println(String.format("[add] -> [%d]" + elem, index));
			super.add(index, elem);
		}
		
		public boolean add(E elem) {
			return standardAdd(elem);
		}
		
		public boolean addAll(Collection<? extends E> c) {
			return standardAddAll(c);
		}

	}

}
